import { init } from "@rematch/core";
import createLoadingPlugin, { LoadingConfig } from "@rematch/loading";
import { connectRouter, routerMiddleware } from "connected-react-router";
import { ExtraModelsLoading } from "./types";
import history from "./history";
import * as models from "./models";

/**
 * asNumber：默认是false，如果设置为true，那么状态就是异步被调用的次数
 * name：loading model的name，默认是loading
 * whitelist：白名单，一个 action 列表，只收集在列表中的action的状态。命名使用“model名称” / “action名称”，{ whitelist: ['count/addOne'] })
 * blacklist：黑名单一个 action 列表，不使用 loading 指示器。
 */
const loadingOptions: LoadingConfig = {};
const loadingPlugin = createLoadingPlugin<typeof models, any, typeof loadingOptions>(loadingOptions);

const store = init<typeof models, ExtraModelsLoading>({
  models,
  plugins: [loadingPlugin],
  redux: {
    middlewares: [routerMiddleware(history)],
    reducers: {
      router: connectRouter(history),
    },
  },
});

export default store;

export * from "./types";
